package com.pcbly.web.components.license;

import java.util.Date; 
import java.util.Map;

@SuppressWarnings("unchecked")
public class OfficeLicense extends License {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4709386007715879608L;
	
	private License license;

	public OfficeLicense(License license) {
		this.license = license;
	}

	public long getID() {
		return license.getLicenseData().getId();
	}

	public void setID(long l) {
		license.getLicenseData().setId(l);
	}

	public String getName() {
		return license.getLicenseData().getName();
	}

	public void setName(String module) {
		license.getLicenseData().setName(module);
	}

	public Date getCreationDate() {
		return license.getLicenseData().getCreateDate();
	}

	public Version getVersion() {
		return license.getLicenseData().getVersion();
	}

	public void setVersion(Version version) {
		license.getLicenseData().setVersion(version);
	}

	public void setCreationDate(Date date) {
		license.getLicenseData().setCreateDate(date);
	}

	public  Client getClient() {
		return license.getLicenseData().getClient();
	}

	public void setClient( Client client) {
		license.getLicenseData().setClient(client);
	} 

	public Map getProperties() {
		return license.getLicenseData().getProperties();
	}

	public void setProperties(Map map) {
		license.getLicenseData().setProperties(map);
	}

	public String getSignature() {
		return license.getLicenseData().getSignature();
	}

	public void setSignature(String module) {
		license.getLicenseData().setSignature(module);
	}

	public String getType() {
		return license.getLicenseData().getType();
	}

	public void setType(String type) {
		license.getLicenseData().setType(type);
	}

	public byte[] getFingerprint() {
		return license.getFingerprint();
	}

	public boolean equals(Object o) {
		return license.equals(o);
	}

	public int hashCode() {
		return license.hashCode();
	}

	public String toString() {
		return license.toString();
	}

	public String toXML() {
		return license.toXML();
	}

	public String getEdition() {
		return license.getLicenseData().getEdition();
	}

	public void setEdition(String module) {
		license.getLicenseData().setEdition(module);
	}

	public int getNumClusterMembers() {
		int allowedMembers = 1;
		String s = (String) getProperties().get(
				OfficeLicenseManager.OfficeLicenseProperty.numClusterMembers
						.name());
		if (s != null) {
			int numClusterMembers = Integer.parseInt(s);
			if (numClusterMembers < allowedMembers)
				allowedMembers = numClusterMembers;
			if (allowedMembers == 1)
				allowedMembers = numClusterMembers;
		}
		return allowedMembers;
	}

	public int getNumberOfClusterMembers() {
		String s = (String) getProperties().get(
				OfficeLicenseManager.OfficeLicenseProperty.numClusterMembers
						.name());
		if (s != null)
			return Integer.parseInt(s);
		else
			return -1;
	}

	public Date getExpirationDate() {
		String s = (String) getProperties().get(
				OfficeLicenseManager.OfficeLicenseProperty.expirationDate
						.name());
		if(s!=null){
			try{
				return getLicenseData().parseDate(s);
			}catch(Exception e){
				return null;
			}
		}
		return null;
		
	}

}
